class H5time < ActiveRecord::Base
  serialize :startTime
  serialize :endTime
  serialize :itinerary
  serialize :warnTime
  serialize :invite
  serialize :remark

  def self.getH5time(object_id)
    _h5time = self.where(:object_id =>object_id)
    unless _h5time.blank?
      _h5time_data = []
      _h5time.each do |h5time|
        data = {
          :key => h5time.key.to_s,
          :title => h5time.title.to_s,
          :address => h5time.address.to_s,
          :type => h5time.address.to_s,
          :startTime => h5time.startTime,
          :endTime => h5time.endTime,
          :itinerary => h5time.itinerary,
          :warnTime => h5time.warnTime,
          :invite => h5time.invite,
          :remark => h5time.remark
        }
        _h5time_data << data
      end
    else
      nil
    end
  end

  def self.postH5time(object_id,data_value)
    data = data_value.to_h
    data["object_id"] = object_id
    Rails.logger.info("====time====>#{data}")
    arr_data = []
    data.each do |dtk,dtv|
      if(dtv.class.to_s == "Hashie::Mash")
        data[dtk] = dtv.to_h
      end
    end
    arr_data << data
    self.create(arr_data)
  end
  def self.putH5time
  end
  def self.deleteh5time(object_id, key)
    _h5time = self.find_by(:object_id => object_id, :key => key)
    unless _h5time.blank?
      _h5time.destroy
    end
  end
end
